﻿<UserControl x:Class="ScrumFactory.Team.MembersList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"     
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"       
             xmlns:SF_Helpers_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"
             
             x:Name="thisView"
             
             mc:Ignorable="d"                   
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding RefreshCommand}" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <DataTemplate x:Key="MemberDataTemplate">
            <Grid Width="300" Margin="0,0,10,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <ContentControl                        
                        DataContext="{Binding MemberProfile}"
                        Grid.Column="0"
                        Margin="0,3,20,3"
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        Style="{StaticResource MemberImageControlStyle}"/>
                <StackPanel Grid.Column="1">
                    <TextBlock TextTrimming="CharacterEllipsis" >
                        <Hyperlink 
                            Command="{Binding Model.ShowDetailWindowCommand, ElementName=thisView}" Foreground="{StaticResource LinkItemCover}" FontWeight="Normal"
                            CommandParameter="{Binding .}">
                            <Run Text="{Binding MemberProfile.FullName}" FontSize="{StaticResource BigFontSize}" />        
                        </Hyperlink>
                    </TextBlock>
                    
                        
                    <TextBlock Text="{Binding MemberProfile.CompanyName}" Foreground="{StaticResource AlertBrush}" FontSize="{StaticResource NormalFontSize}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis">
                        <TextBlock.Style>
                            <Style>
                                <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsContactMember}" Value="True">
                                        <Setter Property="TextBlock.Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <TextBlock>                                
                                    <Hyperlink                                           
                                            SF_Comp:CommandBehavior.RoutedEventName="Click" Foreground="{StaticResource LinkItemCover}" FontWeight="Normal"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding SendEmailCommand}">
                                        <Run Text="{Binding MemberProfile.EmailAccount}" FontSize="{StaticResource SmallFontSize}" />    
                                    </Hyperlink>                                    
                 </TextBlock>
                    <TextBlock Text="{Binding MemberProfile.Skills}" Foreground="{StaticResource SubTextBrush}" TextWrapping="Wrap" FontSize="{StaticResource SmallFontSize}" TextTrimming="CharacterEllipsis"/>
                </StackPanel>
                <Path                  
                    Grid.Column="2"
                    StrokeLineJoin="Round" SnapsToDevicePixels="True"
                    DataContext="{Binding MemberProfile.DayOccupation}"
                    Style="{StaticResource DayAllocationPath}"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <SF_Helpers:DockWindowContainer>
        <SF_Helpers:PanelLayout 
        SF_Helpers_Ext:SearchBoxExtension.SearchBox="{Binding ElementName=searchTextBox}"                 
        ShowCurrentProjectName="False"
        Title="{Binding PanelName}" Background="Transparent" BorderBrush="Transparent">

            <SF_Helpers:PanelLayout.Toolbar>
                <ToolBar>

                    <!--<MenuItem                    
                        Command="{Binding AddNewMemberCommand}"
                        Header="{x:Static props:Resources.Add_member}">
                        <MenuItem.Icon>
                            <Image Source="\Images\Toolbar\add.png" Width="32" Height="32" />
                        </MenuItem.Icon>
                    </MenuItem>-->
            
                    <MenuItem
                    IsCheckable="True"
                    IsChecked="{Binding OnlyActiveMembers}" 
                    Header="{x:Static props:Resources.only_active}">
                        <MenuItem.Icon>
                            <Image Source="\Images\Toolbar\teamMember.png" Width="32" Height="32" />
                        </MenuItem.Icon>
                    </MenuItem>

                    <ComboBox                                                                                                                       
                        VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,5,0"
                        SelectedValue="{Binding SearchMemberAvailability}"                                
                        Style="{StaticResource MemberAvailabilityComboBox}"/>

                    <TextBlock 
             VerticalAlignment="Center" Margin="0,0,10,0"
            Style="{StaticResource LabelTextBlock}" Text="{x:Static props:Resources.Member_work_load}"/>


                </ToolBar>

            </SF_Helpers:PanelLayout.Toolbar>

            <SF_Helpers:PanelLayout.Content>



                <Grid VerticalAlignment="Stretch">

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>


                    <TextBlock 
                    Grid.Row="0" Margin="0,10,0,0">
                    <TextBlock Text="{Binding Items.Count, ElementName=membersListBox, StringFormat={x:Static props:Resources.n_people_were_found}}" Style="{StaticResource CoverTextTitle}"/>
                    <TextBlock Text="{Binding Filter, StringFormat={x:Static props:Resources._for_X}}" >
                        <TextBlock.Style>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource CoverTextTitle}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Filter}" Value="">
                                        <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Filter}" Value="{x:Null}">
                                        <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </TextBlock>

                    <Border Grid.Row="1" CornerRadius="4" Padding="0,4,0,4"  Background="{StaticResource CoverAreaBrush}" VerticalAlignment="Top">
                    <ListBox    
                    x:Name="membersListBox"
                        VerticalAlignment="Top"
                    
                    ItemContainerStyle="{StaticResource NoHorizontalLineDividedNoSelectionListBoxItem}"
                    SF_Helpers:ItemActivation.ActivationMode="Both"            
                    SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowDetailWindowCommand}"                                    
                    
                    VirtualizingStackPanel.IsVirtualizing="True" 
                    ScrollViewer.IsDeferredScrollingEnabled="True"
                    ItemsSource="{Binding FilteredMembers}" SelectionMode="Single"
            
                    Background="Transparent"
                    BorderThickness="0"
                    HorizontalContentAlignment="Stretch"                                        
                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                    ItemTemplate="{StaticResource MemberDataTemplate}">

                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                    </ListBox>

                    </Border>

                    <ContentControl 
                    Grid.RowSpan="2"
                    Style="{StaticResource LoadingAnimationContent}"/>

                    <Grid         
                    Grid.Row="1"
            HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Image Grid.Column="0" Source="/Images/information.png"  Width="32" Height="32" Stretch="Uniform" Margin="3" VerticalAlignment="Top" />
                        <TextBlock Grid.Column="1" TextWrapping="Wrap" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static props:Resources.No_members_were_found}"/><LineBreak/>
                <TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.No_members_were_found_tooltip}"/>
            </TextBlock>
                        <Grid.Style>
                            <Style>
                                <Setter Property="Grid.Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding ElementName=membersListBox, Path=HasItems}" Value="False"/>
                                            <Condition Binding="{Binding IsLoadingData}" Value="False"/>
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="Grid.Visibility" Value="Visible"/>
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Grid.Style>
                    </Grid>

                    <TextBox 
                    x:Name="searchTextBox"
                    Grid.RowSpan="2"
                    Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}"
                    Style="{StaticResource SearchTextBox}"/>

                </Grid>

            </SF_Helpers:PanelLayout.Content>
        </SF_Helpers:PanelLayout>
    </SF_Helpers:DockWindowContainer>

</UserControl>
